<?php
/***************************************************************************
*                                main.php
 *
 *   Begin date           	: 
 *   Copyright            	: 
 *   Email                	: 
 ***************************************************************************/
defined('PHP5_PHP') or die("Application is stopping!!!");
$smarty->setCompileDir(sprintf($php5RootTempalteCPath, ''));
$tpl = sprintf($php5TemplateFile, $language, 'contactus', 'main.tpl');
if(!is_file($tpl )) {
	die("can not find template");
}
$task 		= trim(php5GetParam($_REQUEST, 'task', ''));
include($php5RootPath."/classes/user.class.php");
include($php5RootPath."/classes/contact.class.php");
$user = new php5User($php5DB);
$user->load($php5Session->getVar("user_id"));
$contact = new Contact($php5DB);
switch($task)
{
	case "update":
		$contact->bind( $_POST );
		if(!trim($contact->name)) {
			$noerr = 0;
			$msgAlert = sprintf($lang['_BLANK_MSG_'], 'Name');
			break;
		}
		if(!trim($contact->phone)) {
			$noerr = 0;
			$msgAlert = sprintf($lang['_BLANK_MSG_'], 'Contact');
			break;
		}
		if(!trim($contact->email)) {
			$noerr = 0;
			$msgAlert = sprintf($lang['_BLANK_MSG_'], 'Email');
			break;
		}						
		
		if(!$contact->enquiry) {
			$msgAlert = sprintf($lang['_BLANK_MSG_'], 'Enquiry');
		} else {
			$arrBCC = array();
			$contact->user_id = 0;
			$contact->update_date = php5GMTTime();
			$contact->store();
			$body = nl2br(sprintf($lang['_MSS_006_'], date('d M Y', php5GMTTime()), $contact->name,$contact->phone, $contact->email,$contact->enquiry));
			//php5Mail( php5GetConfig('config_email'), php5GetConfig('config_sender'), php5GetConfig('config_admin_email'), $lang['_MSS_017_'], $body, 1,'', $arrBCC);
			send_email_all(php5GetConfig('config_admin_email'), $lang['_MSS_005_'], $body);
			$msgAlert = 'We have received your enquiry and we will respond to you as soon as possible';
			$contact = new Contact($php5DB);			
		}
		break;
	default:
		break;
}

$smarty->assign('name', $contact->name);
$smarty->assign('phone', $contact->phone);
$smarty->assign('email', $contact->email);
$smarty->assign('enquiry', $contact->enquiry);
$smarty->assign('config_contact', php5GetConfig('config_contact'));

$smarty->assign('action', sefBuild($php5WebPath, 'index.php?o=contact', 1));
$smarty->assign('main', $smarty->fetch($tpl));



